package com.hns.can.energy.service;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hns.can.base.entity.SysCodeDscEntity;
import com.hns.can.common.aop.orgTree.LeftOrgAnnotation;
import com.hns.can.common.constants.GlobalConst;
import com.hns.can.common.entity.BaseEntity;
import com.hns.can.common.formula.FillCodeDscValue;
import com.hns.can.common.formula.FillParamsVo;
import com.hns.can.common.service.CacheTaskManager;
import com.hns.can.common.vo.SysCacheVo;
import com.hns.can.energy.entity.AppOilPriceEntity;
import com.hns.can.energy.vo.EnergyExportVo;
import com.hns.can.energy.vo.EnergyVo;
import com.hns.can.energy.vo.NewEnergy;

import com.hns.can.master.entity.BaseCarInfoEntity;
import com.hns.can.master.entity.BaseParkingLotInfoEntity;
import com.hns.can.master.entity.CommEnerConsStatInfoEntity;
import com.hns.can.master.vo.CarPostDataVo;


import com.hns.frame.dao.SqlMapDao;
import com.hns.frame.mybatis.Pagination;
import com.hns.frame.service.CommonService;
import com.hns.tool.pub.PubUtil;
import com.hns.tool.pub.UtilString;

/**
 * 车辆能耗service
 * @author:Fisher
 * @email:zhuangcaijin@126.com
 * @version Revision 2.0.0
 */
@Service
public class OilPriceService extends CommonService {
    
    @Autowired
    private FillCodeDscValue codeDscValue;
    @Autowired
    public SqlMapDao sqlMapDao;
    @Autowired
    private CacheTaskManager cacheTaskManager;
    
    @Transactional
    @SuppressWarnings({ "static-access", "unchecked" })
    public Pagination searchRefuelQuery(EnergyVo vo)  {
        Pagination page = this.myBatisPage("oilPrice.searchRefuelQueryCount", "oilPrice.searchRefuelQuery", vo, AppOilPriceEntity.class);
        List list = page.getData();
        HashMap map = new HashMap();
        map.put("cityId", vo.getProvinceId());
        codeDscValue.fillCodeDscValue(list, map);
        page.setData(list);
        return page;
    }
    
    @Transactional
    @SuppressWarnings({ "static-access", "unchecked" })
    public Pagination addEnergyPriceSet(AppOilPriceEntity entity)  {
    	
    	commonEntityDao.save(entity);
        return null;
    }
    
    @Transactional
    @SuppressWarnings({ "static-access", "unchecked" })
    public Pagination updateEnergyPriceSet(AppOilPriceEntity entity)  {
    	commonEntityDao.update(entity);
        return null;
    }
    
    @Transactional
    @SuppressWarnings({ "static-access", "unchecked" })
    public Object getEnergyInfoById(String id)  {
    	Map<String,String> map = new HashMap<String,String>();
    	map.put("id", id);
    	AppOilPriceEntity aope = this.commonEntityDao.find(id, AppOilPriceEntity.class);
    	return aope;
    }
    
    @Transactional
    @SuppressWarnings({ "static-access", "unchecked" })
    public Pagination delEnergyInfo(String id)  {
    	AppOilPriceEntity aope = this.commonEntityDao.find(id, AppOilPriceEntity.class);
    	commonEntityDao.delete(aope);
        return null;
    }
    
    /**
     * 得到车辆信息list对象
     * @param dataVo
     * @return
     * @throws Exception
     * @author:chenl
     * @email:370238764@qq.com
     */
    @SuppressWarnings({"unchecked"})
    @Transactional
    public List<BaseEntity> getEnergyInfoList(EnergyExportVo dataVo) throws Exception {
    	List<BaseEntity> list = PubUtil.convertListMapToObject(this.sqlMapDao.selectList("oilPrice.searchRefuelQuery", dataVo), AppOilPriceEntity.class);
    	Map<String,String> mapTmp = new HashMap<String,String>();
        mapTmp.put("provinceId", "ADS00000");
        mapTmp.put("cityId", dataVo.getProvinceId());
        mapTmp.put("oilType", "FUT00000");
        codeDscValue.fillCodeDscValue(list, mapTmp);
        return list;
    }
    
    @SuppressWarnings("static-access")
    public List<AppOilPriceEntity> selectEnergyTime(String cityId)  {
    	Map<String,String> map = new HashMap<String,String>();
    	map.put("cityId", cityId);
    	List<AppOilPriceEntity> list=PubUtil.convertListMapToObject(sqlMapDao.selectList("oilPrice.searchOilAdjustDate", map), AppOilPriceEntity.class);
        //System.out.println(list.toString());
    	return list;
    }
    
    

}
